﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

namespace VisionCloud.Core.Migrations
{
    public partial class initDb : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            //migrationBuilder.AlterDatabase()
            //    .Annotation("Npgsql:PostgresExtension:uuid-ossp", ",,");

            migrationBuilder.CreateTable(
                name: "MsDevice",
                columns: table => new
                {
                    RegisterId = table.Column<Guid>(type: "uuid", nullable: false),
                    IsDeleted = table.Column<bool>(type: "bool", nullable: false),
                    CreatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    CreatedDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    LastUpdatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    LastUpdatedDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    USBKeyNO = table.Column<string>(type: "varchar(512)", nullable: true),
                    FaroNO = table.Column<string>(type: "varchar(512)", nullable: true),
                    SurfaceNO = table.Column<string>(type: "varchar(512)", nullable: true),
                    ProductDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    SaleDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    DeviceKey = table.Column<string>(type: "varchar(512)", nullable: true),
                    UserCode = table.Column<string>(type: "varchar(255)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MsDevice", x => x.RegisterId);
                });

            migrationBuilder.CreateTable(
                name: "MsProject",
                columns: table => new
                {
                    YunProjectGuid = table.Column<Guid>(nullable: false),
                    IsDeleted = table.Column<bool>(type: "bool", nullable: false),
                    CreatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    CreatedDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    LastUpdatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    LastUpdatedDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    DeviceGuid = table.Column<Guid>(type: "uuid", nullable: false),
                    ProjectId = table.Column<Guid>(type: "uuid", nullable: false),
                    Name = table.Column<string>(type: "varchar(255)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MsProject", x => x.YunProjectGuid);
                });

            migrationBuilder.CreateTable(
                name: "MsReport",
                columns: table => new
                {
                    YunReportGuid = table.Column<Guid>(nullable: false),
                    IsDeleted = table.Column<bool>(type: "bool", nullable: false),
                    CreatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    CreatedDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    LastUpdatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    LastUpdatedDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    DeviceGuid = table.Column<Guid>(type: "uuid", nullable: false),
                    YunProjectGuid = table.Column<Guid>(type: "uuid", nullable: false),
                    TaskReportId = table.Column<Guid>(type: "uuid", nullable: false),
                    ProjectId = table.Column<Guid>(type: "uuid", nullable: false),
                    TaskId = table.Column<Guid>(type: "uuid", nullable: false),
                    FileId = table.Column<Guid>(type: "uuid", nullable: false),
                    YunTaskId = table.Column<Guid>(type: "uuid", nullable: false),
                    RobotId = table.Column<string>(type: "varchar(64)", nullable: true),
                    ReportType = table.Column<int>(type: "int4", nullable: false),
                    ReportName = table.Column<string>(type: "varchar(255)", nullable: true),
                    ReportPath = table.Column<string>(type: "varchar(500)", nullable: true),
                    IsNew = table.Column<bool>(type: "bool", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MsReport", x => x.YunReportGuid);
                });

            migrationBuilder.CreateTable(
                name: "MsTask",
                columns: table => new
                {
                    YunTaskGuid = table.Column<Guid>(nullable: false),
                    IsDeleted = table.Column<bool>(type: "bool", nullable: false),
                    CreatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    CreatedDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    LastUpdatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    LastUpdatedDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    YunProjectGuid = table.Column<Guid>(type: "uuid", nullable: false),
                    DeviceGuid = table.Column<Guid>(type: "uuid", nullable: false),
                    TaskId = table.Column<Guid>(type: "uuid", nullable: false),
                    TaskName = table.Column<string>(type: "varchar(255)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MsTask", x => x.YunTaskGuid);
                });

            migrationBuilder.CreateTable(
                name: "MsUserToProject",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
                    CreatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    CreatedDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    YunUserGuid = table.Column<Guid>(nullable: false),
                    YunProjectGuid = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MsUserToProject", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MsUserToUser",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
                    YunUserGuidLeft = table.Column<Guid>(nullable: false),
                    YunUserGuidRight = table.Column<Guid>(nullable: false),
                    UserRelationship = table.Column<string>(type: "varchar(150)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MsUserToUser", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SysDevice",
                columns: table => new
                {
                    DeviceGuid = table.Column<Guid>(nullable: false),
                    IsDeleted = table.Column<bool>(type: "bool", nullable: false),
                    CreatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    CreatedDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    LastUpdatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    LastUpdatedDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    DeviceSoftwareVersion = table.Column<string>(type: "varchar(255)", nullable: true),
                    DeviceNumber = table.Column<string>(type: "varchar(500)", nullable: true),
                    ComputerNumber = table.Column<string>(type: "varchar(500)", nullable: true),
                    ComputerSystemVersion = table.Column<string>(type: "varchar(100)", nullable: true),
                    ComputerType = table.Column<string>(type: "varchar(50)", nullable: true),
                    ComputerDateOfProduction = table.Column<DateTime>(type: "timestamp(0)", nullable: true),
                    ScannerNumber = table.Column<string>(type: "varchar(500)", nullable: true),
                    ScannerType = table.Column<string>(type: "varchar(50)", nullable: true),
                    ScannerDateOfProduction = table.Column<DateTime>(type: "date", nullable: false),
                    ScannerFirmwareVersion = table.Column<string>(type: "varchar(100)", nullable: true),
                    IsActive = table.Column<bool>(nullable: false),
                    ActiveDate = table.Column<DateTime>(type: "timestamp(0)", nullable: true),
                    ActiveUserGuid = table.Column<Guid>(nullable: true),
                    CustomerCompanyName = table.Column<string>(type: "varchar(500)", nullable: true),
                    ComputerExpire = table.Column<DateTime>(type: "timestamp(0)", nullable: true),
                    ScannerExpire = table.Column<DateTime>(type: "timestamp(0)", nullable: true),
                    DeviceExpire = table.Column<DateTime>(type: "timestamp(0)", nullable: true),
                    EncryptedDogNumber = table.Column<string>(type: "varchar(255)", nullable: false),
                    EncryptedDogType = table.Column<string>(type: "varchar(50)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysDevice", x => x.DeviceGuid);
                });

            migrationBuilder.CreateTable(
                name: "SysUser",
                columns: table => new
                {
                    UserId = table.Column<Guid>(nullable: false),
                    IsDeleted = table.Column<bool>(type: "bool", nullable: false),
                    CreatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    CreatedDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    LastUpdatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    LastUpdatedDate = table.Column<DateTime>(type: "timestamp(0)", nullable: false),
                    Name = table.Column<string>(type: "varchar(32)", nullable: false),
                    Code = table.Column<string>(type: "varchar(32)", nullable: false),
                    Password = table.Column<string>(type: "varchar(256)", nullable: false),
                    IsLocked = table.Column<bool>(nullable: false),
                    UserType = table.Column<int>(nullable: false),
                    Status = table.Column<int>(nullable: false),
                    Email = table.Column<string>(type: "varchar(50)", nullable: true),
                    PhoneNumber = table.Column<string>(type: "varchar(50)", nullable: true),
                    AccountNumber = table.Column<string>(type: "varchar(50)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysUser", x => x.UserId);
                });


            migrationBuilder.CreateIndex(
                name: "IX_MsProject_DeviceGuid",
                table: "MsProject",
                column: "DeviceGuid");

            migrationBuilder.CreateIndex(
                name: "IX_MsProject_Name",
                table: "MsProject",
                column: "Name");

            migrationBuilder.CreateIndex(
                name: "IX_MsProject_ProjectId",
                table: "MsProject",
                column: "ProjectId");

            migrationBuilder.CreateIndex(
                name: "IX_MsReport_TaskId",
                table: "MsReport",
                column: "TaskId");

            migrationBuilder.CreateIndex(
                name: "IX_MsReport_TaskReportId",
                table: "MsReport",
                column: "TaskReportId");

            migrationBuilder.CreateIndex(
                name: "IX_MsReport_YunProjectGuid",
                table: "MsReport",
                column: "YunProjectGuid");

            migrationBuilder.CreateIndex(
                name: "IX_MsReport_YunTaskId",
                table: "MsReport",
                column: "YunTaskId");

            migrationBuilder.CreateIndex(
                name: "IX_MsTask_DeviceGuid",
                table: "MsTask",
                column: "DeviceGuid");

            migrationBuilder.CreateIndex(
                name: "IX_MsTask_TaskId",
                table: "MsTask",
                column: "TaskId");

            migrationBuilder.CreateIndex(
                name: "IX_MsUserToProject_YunProjectGuid",
                table: "MsUserToProject",
                column: "YunProjectGuid");

            migrationBuilder.CreateIndex(
                name: "IX_MsUserToProject_YunUserGuid",
                table: "MsUserToProject",
                column: "YunUserGuid");

            migrationBuilder.CreateIndex(
                name: "IX_MsUserToUser_YunUserGuidLeft",
                table: "MsUserToUser",
                column: "YunUserGuidLeft");

            migrationBuilder.CreateIndex(
                name: "IX_MsUserToUser_YunUserGuidRight",
                table: "MsUserToUser",
                column: "YunUserGuidRight");

            migrationBuilder.CreateIndex(
                name: "IX_SysDevice_DeviceNumber",
                table: "SysDevice",
                column: "DeviceNumber");

            migrationBuilder.CreateIndex(
                name: "IX_SysDevice_EncryptedDogNumber_EncryptedDogType",
                table: "SysDevice",
                columns: new[] { "EncryptedDogNumber", "EncryptedDogType" });

        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MsDevice");

            migrationBuilder.DropTable(
                name: "MsProject");

            migrationBuilder.DropTable(
                name: "MsReport");

            migrationBuilder.DropTable(
                name: "MsTask");

            migrationBuilder.DropTable(
                name: "MsUserToProject");

            migrationBuilder.DropTable(
                name: "MsUserToUser");

            migrationBuilder.DropTable(
                name: "SysDevice");

            migrationBuilder.DropTable(
                name: "SysLog");

            migrationBuilder.DropTable(
                name: "SysRolePermission");

            migrationBuilder.DropTable(
                name: "SysUserRole");

            migrationBuilder.DropTable(
                name: "SysMenuFunc");

            migrationBuilder.DropTable(
                name: "SysRole");

            migrationBuilder.DropTable(
                name: "SysUser");

            migrationBuilder.DropTable(
                name: "SysMenu");
        }
    }
}
